package gocache

import (
	"fmt"
	"log"
	"net/http"
	"strings"
)

const defaultBasePath = "go_cache"

type HttpPool struct {
	self     string
	bashPath string
}

func NewHttpPool(self string) *HttpPool {
	return &HttpPool{
		self:     self, // 127.0.0.1:6000
		bashPath: defaultBasePath,
	}
}

func (p *HttpPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// 所有的请求都交给该方法处理
	if !strings.HasPrefix(r.URL.Path, defaultBasePath) {
		panic("HTTPPool serving unexpected path: " + r.URL.Path)
	}
	p.Log("%s %s", r.Method, r.URL.Path)
}

// Log info with server name
func (p *HttpPool) Log(format string, v ...interface{}) {
	log.Printf("[Server %s] %s", p.self, fmt.Sprintf(format, v...))
}
